package com.example.hellospringboot.SpringSecurity.config;


import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//        设置密码编码器
        BCryptPasswordEncoder bCryptPasswordEncoder=new BCryptPasswordEncoder();
        auth.inMemoryAuthentication()
                .passwordEncoder(bCryptPasswordEncoder)
                .withUser("zhangsan")
                .password(bCryptPasswordEncoder.encode("123456")).roles("common")
                .and()
                .withUser("admin").password(bCryptPasswordEncoder.encode("123456")).roles("vip");
    }
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);
    }


}
